package com.syl.starter.itools.framework.utils;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @author syl
 * @create 2019-01-21 14:09
 **/
public class JUnitUtils {
    public static final String JUNIT_RUNNERS_STRING = "junit.runners";

    /**
     * 检测是否在JUnit运行
     * @return
     */
    public static Boolean isRunning() {
        StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
        if(stackTrace == null)
            return false;
        List stackList = Arrays.asList(stackTrace);
        for (Iterator i = stackList.iterator(); i.hasNext(); ) {
            String stackString = i.next().toString();
            if (stackString.lastIndexOf(JUNIT_RUNNERS_STRING) > -1) {
                return true;
            }
        }
        return false;
    }

}
